﻿#ifndef VIDEODECODERTHREAD_H
#define VIDEODECODERTHREAD_H
#include <QMutex>
#include<QThread>
#include <QVideoFrame>
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/mathematics.h"
#include "libavutil/time.h"
#include "libswscale/swscale.h"
#include"libswresample/swresample.h"
#include "libavutil/imgutils.h"
}
class VideoDecoderThread:public QThread
{
    Q_OBJECT
public:
    VideoDecoderThread(QObject * pParent,AVCodecContext * pCodecCtx, int duration,AVPixelFormat fmt);

    void addPacket(AVPacket * pPacket);
    void quit();
    // QThread interface
protected:
    AVPacket *getPacket();
    void playFrame(AVFrame * pFrame);
    void run();
signals:
    void updateFrame(QImage * img);
private:
    QList<AVPacket *>m_pPacket;
    QMutex m_lockPacket;
    AVCodecContext * m_pCodecCtx;
    AVFrame  * m_pFrameDec = NULL; //解码出的视频帧
    AVFrame  * m_pFrameCPU = NULL; //转换后的视频帧
    AVFrame * m_pAVFrameRGB = NULL;
    uint8_t * m_OutBuf= NULL;
    struct SwsContext *m_pSwsCtx = NULL; //转换环境
    int m_nDuration;
    bool m_bRun;
    QString m_strPath;
    int m_nWidth=0;
    int m_nHeight=0;
    AVPixelFormat m_hw_fmt;
};

#endif // VIDEODECODERTHREAD_H
